pandas.DataFrame.cumsum |
您所在的位置:网站首页 › pandas npwhere › pandas.DataFrame.cumsum |
Return cumulative sum over a DataFrame or Series axis. Returns a DataFrame or Series of the same size containing the cumulative sum. Parameters axis{0 or ‘index’, 1 or ‘columns’}, default 0The index or the name of the axis. 0 is equivalent to None or ‘index’. For Series this parameter is unused and defaults to 0. skipnabool, default TrueExclude NA/null values. If an entire row/column is NA, the result will be NA. *args, **kwargsAdditional keywords have no effect but might be accepted for compatibility with NumPy. Returns Series or DataFrameReturn cumulative sum of Series or DataFrame. See also core.window.expanding.Expanding.sumSimilar functionality but ignores NaN values. DataFrame.sumReturn the sum over DataFrame axis. DataFrame.cummaxReturn cumulative maximum over DataFrame axis. DataFrame.cumminReturn cumulative minimum over DataFrame axis. DataFrame.cumsumReturn cumulative sum over DataFrame axis. DataFrame.cumprodReturn cumulative product over DataFrame axis. Examples Series >>> s = pd.Series([2, np.nan, 5, -1, 0]) >>> s 0 2.0 1 NaN 2 5.0 3 -1.0 4 0.0 dtype: float64By default, NA values are ignored. >>> s.cumsum() 0 2.0 1 NaN 2 7.0 3 6.0 4 6.0 dtype: float64To include NA values in the operation, use skipna=False >>> s.cumsum(skipna=False) 0 2.0 1 NaN 2 NaN 3 NaN 4 NaN dtype: float64DataFrame >>> df = pd.DataFrame([[2.0, 1.0], ... [3.0, np.nan], ... [1.0, 0.0]], ... columns=list('AB')) >>> df A B 0 2.0 1.0 1 3.0 NaN 2 1.0 0.0By default, iterates over rows and finds the sum in each column. This is equivalent to axis=None or axis='index'. >>> df.cumsum() A B 0 2.0 1.0 1 5.0 NaN 2 6.0 1.0To iterate over columns and find the sum in each row, use axis=1 >>> df.cumsum(axis=1) A B 0 2.0 3.0 1 3.0 NaN 2 1.0 1.0 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |